import 	Vue 		from 'vue';
import	App 		from '@/app.vue';
import 	router 		from '@/router/router.js'
import VueClipboard from 'vue-clipboard2';
import Vant 		from 'vant';
import { Toast,Dialog } 	from 'vant';
import util 		from './util.js'
import VueI18n 		from 'vue-i18n'
// import 'vant/lib/index.css';
Vue.use(Vant);
Vue.use(VueClipboard);
Vue.use(VueI18n)
Vue.use(Toast,Dialog);
import 	'@/static/css/reset.css'

import "babel-polyfill"

Vue.mixin({
	data(){
		return {
			token:''
		}
	},
	computed:{
		version(){
			return util.checkVersion();
		},
		themeIndex(){
			// 0 白色  1 暗色
			let _themeIndex = util.getCookie('themeIndex')
			return Number(_themeIndex)?_themeIndex:0
		},
		locale(){
			return this.$i18n.locale
		},
		isAndroid(){
			// return true
			return !util.client()
		},
		isIphone(){
			// return false
			return util.client()
		},
		isIphoneX(){
			// return false
			return util.isIphoneX()
		},
		isNi(){
			let country = util.getCookie('country');
			return (country === 'nigeria' && this.locale === 'en')?true:false;
		},
		errMsg(){
            return [
               {code:5000,zh:'参数错误',en:'Parameter Error',ja:'パラメーターが間違っています。'}, 
               {code:5100,zh:'系统错误',en:'System Error',ja:'システムエラー'}, 
               {code:5001,zh:'无权限设置返佣比例',en:'No authority to set commission rate',ja:'報酬率を設定する権限がありません。'}, 
               {code:5002,zh:'每个月只能修改一次',en:'You can change it only once a month.',ja:'月に一回のみ変更できます。'}, 
               {code:5003,zh:'返佣比例不在可设置范围内',en:'The commission rate you entered is beyond the settable range.',ja:'ご入力の報酬率は設定範囲を超えています。'}, 
               {code:5005,zh:'搜索不到用户',en:'The user you searched for was not found.',ja:'検索したユーザーが見つかりませんでした。'}, 
            ]
        },
        dialogSystemErr(){
        	return this.locale==='en'?'System is busy, please try again later.':this.locale==='ja'?'システムが忙しいです,しばらくしてからもう一度うお試しください。':'系统繁忙，请稍后再试'
        }
	},
	methods:{
		updateDialog(){
			//弹窗询问是否需要升级
			let version = this.version.toString().split('').join('.')
			Dialog.confirm({
				title: '',
				message: '请升级到最新版本，并进行实名认证<br />当前版本V'+version,
				className:'fullDialog2 fullDialog-all',
				confirmButtonText:'去升级',
				cancelButtonText:'取消',
				cancelButtonColor:'#ccc',
				confirmButtonColor:'#1A76FF',
				overlayClass:'sellType-mark'
			}).then(() => {
				this.goCheckAppVersion();
				console.log('confirm')
			}).catch(() => {
				console.log('cancel')
			})
		},
		goCheckAppVersion(){
			//检查更新
			util.callHandler('checkAppVersion',{},res => {
				console.log(res)
			})
		},
		stop(){
			return false
		},
	},
})

router.beforeEach((to,from,next) => {
	if(util.inBBJ()){
		//嵌入在bbj app中
		if(to.name && !from.name){
			//首次加载当前页面
			next()
		}else{
			//页面之间跳转
			util.callHandler('openUrl',{
				url:window.location.origin+'/otc/index.html#'+to.fullPath,
				title:to.query.title || 'OTC',
				needLogin:true,
				popVC:to.query.death == 1?true:false,		//跳转的时候是否干掉当前页面
				hiddenNav:to.query.hiddenNav?false:true,	//是否全屏
			},res => {
				console.log(res)
			})
		}
	}else{
		//普通浏览器或mykey中
		next();
	}
})

//多语言配置
const i18n = new VueI18n({
    locale: util.readLang(),
    messages: {
        'zh': require('./locales/zh_CN.json'),
        'en': require('./locales/en_US.json'),
        'ja': require('./locales/ja_JA.json'),
    }
})

new Vue({
	el: '#bbj',
	router,
	i18n,
	render: h => h(App),
	components: { App },
})
